package Railroad;

import Railroad.Communication.CommDriver;
import Railroad.Communication.Network.CommDriverNetwork;
import Railroad.Communication.USB.CommDriverUSB;
import java.io.IOException;
import Railroad.GUI.MainWindow;
import Railroad.GUI.RiadenieNavestidiel;

// Spúšťacia trieda main.
public class Main {

    public static void main(String[] args) throws IOException {
        NacitavanieZXML nac = new NacitavanieZXML();
        Zoznam z = new Zoznam(nac.nacitajItemy());
        // ArrayList<TrackItem> pole=nac.nacitajItemy();
        TrackList zoznamTrati = new TrackList();
        zoznamTrati.addTrackList(nac.nacitajCesty(z));
        //zoznamTrati.getaTrackList().get(3).obsadCestu(); 
        RiadenieNavestidiel riadenie=new RiadenieNavestidiel(z);
        riadenie.setZ(zoznamTrati.getaTrackList());
        ObsadzovacCiest obsadzovac = new ObsadzovacCiest(zoznamTrati.getaTrackList(),riadenie);
       
        zoznamTrati.addRiadenie(riadenie);
        CommDriver communication = new CommDriverUSB();
        if (!communication.connect()) {
            communication = new CommDriverNetwork();
            communication.connect();
        }

        MainWindow wnd = new MainWindow(z, obsadzovac,riadenie);
        if (communication.isConnected()) {
            wnd.setCommunication(communication);
        }
        wnd.setVisible(true);

        StatusUpdater updater = new StatusUpdater(z, zoznamTrati, communication);
        updater.addListener(wnd);
        updater.runThread();
    }
}
